using System;
using System.Drawing;
using System.Collections;
using System.Collections.Specialized;
using System.Windows.Forms;
using Commonplace.Domain;
using System.Collections.Generic;

namespace Commonplace
{
	/// <summary>
	/// Summary description for BulkPopulatePopup.
	/// </summary>
	public class BulkPopulatePopup : System.Windows.Forms.Form
	{
		private System.Windows.Forms.CheckBox _useName;
		private System.Windows.Forms.CheckBox _useDescription;
		private System.Windows.Forms.CheckBox _useSource;
		private System.Windows.Forms.CheckBox _useCategories;
		private System.Windows.Forms.CheckBox _useLicense;
		private System.Windows.Forms.TextBox _name;
		private System.Windows.Forms.TextBox _description;
		private System.Windows.Forms.TextBox _source;
		private System.Windows.Forms.TextBox _categories;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.ComboBox _license;
		private System.Windows.Forms.Button _cancel;
		private System.Windows.Forms.Button _ok;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.CheckBox _watch;
		private System.Windows.Forms.RadioButton _watchAll;
		private System.Windows.Forms.RadioButton _watchNone;
        private TextBox _author;
        private CheckBox _useAuthor;
        private TextBox _date;
        private CheckBox _useDate;

		private Commonplace.Domain.License _defaultLicense = null;

		public FileDetailRecord BulkRecord
		{
			get
			{
				FileDetailRecord record = new FileDetailRecord();

				record.Name = _name.Text;
				record.Description = _description.Text;
				record.Source = _source.Text;
				record.Categories = _categories.Text;
				record.License = _license.Text;
				record.Watch = _watchAll.Checked;
                record.Author = _author.Text;
                record.Date = _date.Text;

				return record;
			}
		}

		public bool WatchSet
		{
			get { return _watch.Checked; }
		}

		public BulkPopulatePopup()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

            List<License> licenses = CachedConfig.Instance.Licenses;
            string defaultLicense = CachedConfig.Instance.DefaultLicense;
            _license.Items.AddRange(licenses.ToArray());

			_license.Items.AddRange(licenses.ToArray());

			if (defaultLicense.Length > 0)
			{
				foreach (License license in _license.Items)
				{
					if (license.Name == defaultLicense)
						_defaultLicense = license;
				}
			}

		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(BulkPopulatePopup));
            this._useName = new System.Windows.Forms.CheckBox();
            this._useDescription = new System.Windows.Forms.CheckBox();
            this._useSource = new System.Windows.Forms.CheckBox();
            this._useCategories = new System.Windows.Forms.CheckBox();
            this._useLicense = new System.Windows.Forms.CheckBox();
            this._name = new System.Windows.Forms.TextBox();
            this._description = new System.Windows.Forms.TextBox();
            this._source = new System.Windows.Forms.TextBox();
            this._categories = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this._license = new System.Windows.Forms.ComboBox();
            this._cancel = new System.Windows.Forms.Button();
            this._ok = new System.Windows.Forms.Button();
            this._watch = new System.Windows.Forms.CheckBox();
            this._watchAll = new System.Windows.Forms.RadioButton();
            this._watchNone = new System.Windows.Forms.RadioButton();
            this._author = new System.Windows.Forms.TextBox();
            this._useAuthor = new System.Windows.Forms.CheckBox();
            this._date = new System.Windows.Forms.TextBox();
            this._useDate = new System.Windows.Forms.CheckBox();
            this.SuspendLayout();
            // 
            // _useName
            // 
            this._useName.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this._useName.Location = new System.Drawing.Point(16, 32);
            this._useName.Name = "_useName";
            this._useName.Size = new System.Drawing.Size(88, 24);
            this._useName.TabIndex = 0;
            this._useName.Text = "Name:";
            this._useName.CheckedChanged += new System.EventHandler(this._useName_CheckedChanged);
            // 
            // _useDescription
            // 
            this._useDescription.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this._useDescription.Location = new System.Drawing.Point(16, 56);
            this._useDescription.Name = "_useDescription";
            this._useDescription.Size = new System.Drawing.Size(88, 24);
            this._useDescription.TabIndex = 2;
            this._useDescription.Text = "Description:";
            this._useDescription.CheckedChanged += new System.EventHandler(this._useDescription_CheckedChanged);
            // 
            // _useSource
            // 
            this._useSource.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this._useSource.Location = new System.Drawing.Point(16, 104);
            this._useSource.Name = "_useSource";
            this._useSource.Size = new System.Drawing.Size(88, 24);
            this._useSource.TabIndex = 4;
            this._useSource.Text = "Source:";
            this._useSource.CheckedChanged += new System.EventHandler(this._useSource_CheckedChanged);
            // 
            // _useCategories
            // 
            this._useCategories.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this._useCategories.Location = new System.Drawing.Point(16, 128);
            this._useCategories.Name = "_useCategories";
            this._useCategories.Size = new System.Drawing.Size(88, 24);
            this._useCategories.TabIndex = 6;
            this._useCategories.Text = "Categories:";
            this._useCategories.CheckedChanged += new System.EventHandler(this._useCategories_CheckedChanged);
            // 
            // _useLicense
            // 
            this._useLicense.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this._useLicense.Location = new System.Drawing.Point(16, 206);
            this._useLicense.Name = "_useLicense";
            this._useLicense.Size = new System.Drawing.Size(88, 24);
            this._useLicense.TabIndex = 12;
            this._useLicense.Text = "License:";
            this._useLicense.CheckedChanged += new System.EventHandler(this._useLicense_CheckedChanged);
            // 
            // _name
            // 
            this._name.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this._name.Enabled = false;
            this._name.Location = new System.Drawing.Point(104, 32);
            this._name.Name = "_name";
            this._name.Size = new System.Drawing.Size(216, 20);
            this._name.TabIndex = 1;
            // 
            // _description
            // 
            this._description.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this._description.Enabled = false;
            this._description.Location = new System.Drawing.Point(104, 56);
            this._description.Multiline = true;
            this._description.Name = "_description";
            this._description.Size = new System.Drawing.Size(416, 46);
            this._description.TabIndex = 3;
            // 
            // _source
            // 
            this._source.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this._source.Enabled = false;
            this._source.Location = new System.Drawing.Point(104, 104);
            this._source.Name = "_source";
            this._source.Size = new System.Drawing.Size(416, 20);
            this._source.TabIndex = 5;
            // 
            // _categories
            // 
            this._categories.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this._categories.Enabled = false;
            this._categories.Location = new System.Drawing.Point(104, 128);
            this._categories.Name = "_categories";
            this._categories.Size = new System.Drawing.Size(416, 20);
            this._categories.TabIndex = 7;
            // 
            // label1
            // 
            this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.label1.Location = new System.Drawing.Point(328, 32);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(192, 23);
            this.label1.TabIndex = 9;
            this.label1.Text = "(Unique numbers will be appended)";
            this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // _license
            // 
            this._license.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this._license.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this._license.Enabled = false;
            this._license.Location = new System.Drawing.Point(104, 206);
            this._license.Name = "_license";
            this._license.Size = new System.Drawing.Size(416, 21);
            this._license.TabIndex = 13;
            // 
            // _cancel
            // 
            this._cancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this._cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this._cancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this._cancel.Location = new System.Drawing.Point(448, 256);
            this._cancel.Name = "_cancel";
            this._cancel.Size = new System.Drawing.Size(75, 23);
            this._cancel.TabIndex = 18;
            this._cancel.Text = "&Cancel";
            // 
            // _ok
            // 
            this._ok.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this._ok.DialogResult = System.Windows.Forms.DialogResult.OK;
            this._ok.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this._ok.Location = new System.Drawing.Point(360, 256);
            this._ok.Name = "_ok";
            this._ok.Size = new System.Drawing.Size(75, 23);
            this._ok.TabIndex = 17;
            this._ok.Text = "&OK";
            // 
            // _watch
            // 
            this._watch.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this._watch.Location = new System.Drawing.Point(16, 230);
            this._watch.Name = "_watch";
            this._watch.Size = new System.Drawing.Size(88, 24);
            this._watch.TabIndex = 14;
            this._watch.Text = "Watch:";
            this._watch.CheckedChanged += new System.EventHandler(this._watch_CheckedChanged);
            // 
            // _watchAll
            // 
            this._watchAll.Enabled = false;
            this._watchAll.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this._watchAll.Location = new System.Drawing.Point(112, 230);
            this._watchAll.Name = "_watchAll";
            this._watchAll.Size = new System.Drawing.Size(80, 24);
            this._watchAll.TabIndex = 15;
            this._watchAll.Text = "&All files";
            // 
            // _watchNone
            // 
            this._watchNone.Enabled = false;
            this._watchNone.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this._watchNone.Location = new System.Drawing.Point(200, 230);
            this._watchNone.Name = "_watchNone";
            this._watchNone.Size = new System.Drawing.Size(88, 24);
            this._watchNone.TabIndex = 16;
            this._watchNone.Text = "N&o files";
            // 
            // _author
            // 
            this._author.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this._author.Enabled = false;
            this._author.Location = new System.Drawing.Point(104, 154);
            this._author.Name = "_author";
            this._author.Size = new System.Drawing.Size(416, 20);
            this._author.TabIndex = 9;
            // 
            // _useAuthor
            // 
            this._useAuthor.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this._useAuthor.Location = new System.Drawing.Point(16, 154);
            this._useAuthor.Name = "_useAuthor";
            this._useAuthor.Size = new System.Drawing.Size(88, 24);
            this._useAuthor.TabIndex = 8;
            this._useAuthor.Text = "Author:";
            this._useAuthor.CheckedChanged += new System.EventHandler(this._useAuthor_CheckedChanged);
            // 
            // _date
            // 
            this._date.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this._date.Enabled = false;
            this._date.Location = new System.Drawing.Point(104, 180);
            this._date.Name = "_date";
            this._date.Size = new System.Drawing.Size(416, 20);
            this._date.TabIndex = 11;
            // 
            // _useDate
            // 
            this._useDate.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this._useDate.Location = new System.Drawing.Point(16, 180);
            this._useDate.Name = "_useDate";
            this._useDate.Size = new System.Drawing.Size(88, 24);
            this._useDate.TabIndex = 10;
            this._useDate.Text = "Date:";
            this._useDate.CheckedChanged += new System.EventHandler(this._useDate_CheckedChanged);
            // 
            // BulkPopulatePopup
            // 
            this.AcceptButton = this._ok;
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.CancelButton = this._cancel;
            this.ClientSize = new System.Drawing.Size(536, 284);
            this.Controls.Add(this._date);
            this.Controls.Add(this._useDate);
            this.Controls.Add(this._author);
            this.Controls.Add(this._useAuthor);
            this.Controls.Add(this._watchNone);
            this.Controls.Add(this._watchAll);
            this.Controls.Add(this._watch);
            this.Controls.Add(this._ok);
            this.Controls.Add(this._cancel);
            this.Controls.Add(this._license);
            this.Controls.Add(this.label1);
            this.Controls.Add(this._categories);
            this.Controls.Add(this._source);
            this.Controls.Add(this._description);
            this.Controls.Add(this._name);
            this.Controls.Add(this._useLicense);
            this.Controls.Add(this._useCategories);
            this.Controls.Add(this._useSource);
            this.Controls.Add(this._useDescription);
            this.Controls.Add(this._useName);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MaximizeBox = false;
            this.MaximumSize = new System.Drawing.Size(2000, 320);
            this.MinimizeBox = false;
            this.MinimumSize = new System.Drawing.Size(400, 320);
            this.Name = "BulkPopulatePopup";
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
            this.Text = "Bulk edit multiple files...";
            this.ResumeLayout(false);
            this.PerformLayout();

		}
		#endregion

		private void _useName_CheckedChanged(object sender, System.EventArgs e)
		{
			_name.Enabled = _useName.Checked;

			if (false == _name.Enabled)
				_name.Clear();
		}

		private void _useDescription_CheckedChanged(object sender, System.EventArgs e)
		{
            _description.Enabled = _useDescription.Checked;	

			if (false == _description.Enabled)
				_description.Clear();
		}

		private void _useSource_CheckedChanged(object sender, System.EventArgs e)
		{
			_source.Enabled = _useSource.Checked;
			
			if (false == _source.Enabled)
				_source.Clear();
		}

		private void _useCategories_CheckedChanged(object sender, System.EventArgs e)
		{
			_categories.Enabled = _useCategories.Checked;

			if (false == _categories.Enabled)
				_categories.Clear();
		}

		private void _useLicense_CheckedChanged(object sender, System.EventArgs e)
		{
			_license.Enabled = _useLicense.Checked;

			if (true == _license.Enabled)
			{
				if (null != _defaultLicense)
				{
					_license.SelectedItem = _defaultLicense;
					//_license.SelectionStart = 0;
				}
			}
			else
				_license.Text = "";
		}

		private void _watch_CheckedChanged(object sender, System.EventArgs e)
		{
			_watchAll.Enabled = _watchNone.Enabled = _watch.Checked;

			if (true == _watch.Checked)
				_watchAll.Checked = true;
		}

        private void _useAuthor_CheckedChanged(object sender, EventArgs e)
        {
            _author.Enabled = _useAuthor.Checked;

            if (false == _author.Enabled)
                _author.Clear();
        }

        private void _useDate_CheckedChanged(object sender, EventArgs e)
        {
            _date.Enabled = _useDate.Checked;

            if (false == _date.Enabled)
                _date.Clear();
        }
	}
}
